home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
C
/
Comet2.1.3.cpt
/
emlib
/
key.c
< prev
next >
Wrap
Text File
|
1991-08-02
|
39KB
|
2,067 lines
/*
Copyright Cornell University 1986. All rights are reserved.
*/
#include <em.h>
#include <h19.h>
#include <macdefs.h>
#include <resdefs.h>
#include <rcodes.h>
#include <3270.h>
short keytron; /* key vector trap has been set up, hazardous to some DA's & succeeding apps */
extern char hexchar();
extern short resfid; /* resource file descriptor */
#define BADKEY '\317'
#define MAXKEYCODE 51
/* keycode -> control char mapping for option key
ASDFHGZXCV
.BQWERYT.2
..6....-..
]OU[IP.LJ.
K.\./NM
*/
char optkeymap[MAXKEYCODE] = "\
\001\023\004\006\010\007\032\030\003\026\
\317\002\021\027\005\022\031\024\317\000\
\317\317\036\317\317\317\317\037\317\317\
\035\017\025\033\011\020\317\014\012\317\
\013\317\034\317\177\016\015\317\317\000";
/* test a character to see if it should produce a control character */
makecontrol(thechar, keycode)
unsigned char * thechar;
unsigned char keycode;
{
if (keycode < MAXKEYCODE - 1) {
if (optkeymap[keycode] != BADKEY) {
/* if good match */
*thechar = optkeymap[keycode];
return(TRUE);
}
}
return(FALSE);
}
/* is the option key down? */
optkeydown()
{
KeyMap thekeys;
GetKeys(&thekeys);
if (thekeys[1] & (long) 0x0004)
/* yup, it's down alright */
return(TRUE);
else
return(FALSE);
}
/* is the control key down? */
ctlkeydown()
{
KeyMap thekeys;
GetKeys(&thekeys);
if (thekeys[1] & (long) 0x8000)
/* yup, it's down alright */
return(TRUE);
else
return(FALSE);
}
/* place the action codes associated with a key on the action queue;
distinguishes between ibm or ascii mode, old and new keyboards,
function or character mapping for keypad */
keymap(keycode, thechar, modifiers)
unsigned char keycode;
unsigned char thechar;
unsigned short modifiers;
{
short count;
unsigned long keyid;
struct token * actptr;
extern SysEnvRec environs;
if (keydp->keyaltset)
/* turn off the mouse state: button down in key dialog interpreted as ALT */
modifiers &= ~btnState;
else
modifiers |= btnState;
/* switch the -/+ key for the Standard keypad if user has configured it... */
if (keypadswitch && environs.keyBoardType == envStandADBKbd) {
if (keycode == 0x4e) {
/* - key, make it a + key */
keycode = 0x45;
thechar = '+';
}
else if (keycode == 0x45) {
/* + key, make it a - key */
keycode = 0x4e;
thechar = '-';
}
}
/* TODO the following derivation of keyid should be unnecessary */
keyid = modifiers;
keyid <<= 16;
keyid |= (keycode << 8) & 0xFFFF;
keyid |= thechar & 0x00FF;
if (keydp->dokeymacros && (actptr = keyxfind(keyid, &count)) != NULL) {
/* there is a key macro for this key, put actions on the action queue */
for ( ; count--; actptr++) {
keyputaction(actptr->class, actptr->entry);
}
return(0);
}
if (modifiers & cmdKey
&& !(modifiers & optionKey)
&& !(modifiers & shiftKey)
&& !(modifiers & ctrlKey)
)
{
/* of the modifier keys, only the command key/caps lock are down */
if (thechar == '.') {
/* user wants to abort actions */
flushactions(keydp);
return(0);
}
else if (keycode < 52) {
/* and the keycode is less than the keypad codes */
long comm;
/* is this a menu key ? */
if (comm = MenuKey(thechar)) {
docommand(comm);
return(0);
}
}
}
if (keydp->ibm_keymode) {
if (keyboard == OLDKEYBOARD) {
switch (keydp->keypad) {
/* function key keypad in use */
case NORMKEYPAD: {
if (ibmokpnorm(keycode))
return(0);
break;
}
case KEYPAD1:
case KEYPAD2: {
if (ibmokp2(thechar, keycode, modifiers))
return(0);
break;
}
case KEYPAD3: {
if (ibmokp3(keycode))
return(0);
break;
}
}
}
else {
/* uses Mac Plus or higher keyboard, which has different keypad positions! */
if (fkeytest(keycode))
/* Saratoga function key was depressed */
return(0);
switch (keydp->keypad) {
/* function key keypad in use */
case NORMKEYPAD: {
if (ibmnkpnorm(thechar, keycode))
return(0);
break;
}
case KEYPAD1:
case KEYPAD2: {
if (ibmnkp2(thechar, keycode, modifiers))
return(0);
break;
}
case KEYPAD3: {
if (ibmnkp3(thechar, keycode))
return(0);
break;
}
}
}
if (modifiers & optionKey) {
if (ibmtestpf(keycode, modifiers))
/* it was a pf key on main keyboard */
return(0);
}
switch (thechar) {
/* handle the rest of the ibm_keymode keys */
/* TODO fix BS so it is more intelligent */
case BS: {
if (modifiers & cmdKey) {
keyputaction(RSLT_LCAC, DEL_CHAR);
}
else if (modifiers & optionKey) {
keyputaction(RSLT_LCAC, BACKSP_DEL);
}
else if (modifiers & shiftKey) {
keyputaction(RSLT_LCAC, BACKSP_BLANK);
}
else if (keydp->event_reg & INSERT) {
keyputaction(RSLT_LCAC, BACKSP_DEL);
}
else {
keyputaction(RSLT_LCAC, BACKSP_BLANK);
}
break;
}
case TAB: {
if (modifiers & shiftKey || modifiers & cmdKey) {
keyputaction(RSLT_MVCR, BACK_TAB);
}
else
/* regular tab */
keyputaction(RSLT_MVCR, TAB_FWD);
break;
}
case ETX: {
/* Enter key */
if (modifiers & shiftKey) {
keyputaction(RSLT_PFKY, PA1);
}
else if (modifiers & cmdKey) {
keyputaction(RSLT_PFKY, PA3);
}
else if (modifiers & optionKey) {
keyputaction(RSLT_PFKY, CLEAR);
}
else {
keyputaction(RSLT_PFKY, PA2);
}
break;
}
case CR: {
/* make a newline if shifted */
if (modifiers & shiftKey || keydp->crtonl
&& !(modifiers & shiftKey && keydp->crtonl) ) {
/* reverses action when keydp->crtonl true */
keyputaction(RSLT_MVCR, NEW_LINE);
}
else {
keyputaction(RSLT_PFKY, ENTER);
}
break;
}
default: {
/* put out plain character */
if (modifiers & cmdKey)
/* any cmd combos should have been handled already */
break;
keyputaction(RSLT_ASCI, thechar);
}
}
}
else {
/* ASCII keyboard */
if ((modifiers & optionKey) || (modifiers & ctrlKey)) {
/* should we interpret this as a control key? */
char newchar;
switch (thechar) {
case CR: {
if (!keydp->crtonl)
thechar = LF;
keyputaction(RSLT_ASCI, thechar);
return(0);
}
case '`': {
if (!keydp->escmap) {
/* make a '`' rather than an ESC when option down */
thechar = ESC;
}
keyputaction(RSLT_ASCI, thechar);
return(0);
}
case BS: {
if (keydp->ba_bs) {
/* convert to delete */
thechar = DEL;
}
keyputaction(RSLT_ASCI, thechar);
return(0);
}
}
newchar = thechar;
if (!(modifiers & shiftKey) && !(modifiers & cmdKey)
&& ((modifiers & optionKey && !(modifiers & ctrlKey))
|| (modifiers & ctrlKey && !(modifiers & optionKey)))
)
{
/* the Control or Option key is down all by itself */
if (makecontrol(&newchar, keycode)) {
/* interpret as a control key */
keyputaction(RSLT_ASCI, newchar);
return(0);
}
}
return(-1);
}
/* handle things which are spotted by the keycode */
if (keydp->termtype == TERM_VT100
|| keydp->termtype == TERM_VT102
|| keydp->termtype == TERM_VT220
) {
/* we're doing vt100 emulation or vt52 for vt100 */
if ((keydp->mode == VT100MODE && keydp->vtaltkeypad)
|| (keydp->mode != VT100MODE && keydp->vt52altkeypad)) {
/* keypad sends application codes */
if (vtkeychk(&thechar, keycode)) {
return(0);
}
}
else {
if (dovtkeypad(&thechar, keycode)) {
/* character handled by routine */
return(0);
}
}
if (vt200keychk(&thechar, keycode)) {
return(0);
}
}
else {
if (stdkeypad(&thechar, keycode))
/* character handled by routine */
return(0);
}
/* ascii mode responses */
switch (thechar) {
case '`': {
if (keydp->escmap)
/* make an escape */
thechar = ESC;
break;
}
case BS: {
if (!keydp->ba_bs) {
thechar = DEL;
}
break;
}
case CR: {
/* make a newline if shifted or keydp->crtonl set */
if (keydp->mode == VT100MODE) {
if (keydp->vtnewline) {
/* send CR-LF for CR */
keyputaction(RSLT_ASCI, thechar);
if (! (modifiers & shiftKey)) {
thechar = LF;
}
}
}
else if (modifiers & shiftKey || keydp->crtonl) {
thechar = LF;
}
break;
}
}
keyputaction(RSLT_ASCI, thechar);
}
}
/* returns TRUE if routine handles key */
dovtkeypad(charp, keycode)
unsigned char *charp;
unsigned char keycode;
{
if (keyboard == OLDKEYBOARD) {
switch (keycode) {
/* keys from left to right, top to bottom */
/* top 4 keys are PF1 - PF4 */
case 0x47: {
/* Clear == pf1 */
sendvtkeyfunc('P');
break;
}
case 0x4e: {
/* - == pf2 */
sendvtkeyfunc('Q');
break;
}
case 0x46: {
/* '+' key == pf3 */
sendvtkeyfunc('R');
break;
}
case 0x42: {
/* * == pf4 */
sendvtkeyfunc('S');
break;
}
case 0x4d: {
/* / == - on vt100) */
keyputaction(RSLT_ASCI, '-');
break;
}
case 0x48: {
/* ',' == ',' on vt100 */
keyputaction(RSLT_ASCI, ',');
break;
}
case 0x4c: {
/* make ENTER == CR */
*charp = CR;
return(FALSE);
break;
}
default: {
return(FALSE);
}
}
}
else {
/* uses Mac Plus keyboard, which has different keypad positions! */
switch (keycode) {
/* keys from left to right, top to bottom */
case 0x47: {
/* Clear == pf1 */
sendvtkeyfunc('P');
break;
}
case 0x51:
case 0x48: {
/* '=' == pf2 */
if (*charp == CTLUNDERSCORE)
/* down arrow key on mac+ */
keyputaction(RSLT_MVCR, DOWN_ARROW);
else
sendvtkeyfunc('Q');
break;
}
case 0x4b:
case 0x4d: {
/* / == pf3 */
if (*charp == CTLHAT)
/* up arrow key on mac+ */
keyputaction(RSLT_MVCR, UP_ARROW);
else
sendvtkeyfunc('R');
break;
}
case 0x43: /* + key abd */
case 0x42: /* + key mac+ */
{
/* * == pf4 */
if (*charp == CTLRBRACK)
/* right arrow key on mac+ */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
else
sendvtkeyfunc('S');
break;
}
case 0x45: /* + key abd */
case 0x46: /* + key mac+ */
{
/* '+' key == , */
if (*charp == CTLBACKSLASH)
/* left arrow key on mac+ */
keyputaction(RSLT_MVCR, LEFT_ARROW);
else
keyputaction(RSLT_ASCI, ',');
break;
}
case 0x4e: {
/* '-' == '-' */
keyputaction(RSLT_ASCI, '-');
break;
}
case 0x4c: {
/* make ENTER == Enter */
*charp = CR;
return(FALSE);
break;
}
case 0x7b: {
/* left arrow key saratoga */
keyputaction(RSLT_MVCR, LEFT_ARROW);
break;
}
case 0x7c: {
/* right arrow key saratoga */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
break;
}
case 0x7d: {
/* down arrow key saratoga */
keyputaction(RSLT_MVCR, DOWN_ARROW);
break;
}
case 0x7e: {
/* up arrow key saratoga */
keyputaction(RSLT_MVCR, UP_ARROW);
break;
}
default: {
return(FALSE);
}
}
}
return(TRUE);
}
vtkeychk(charp, keycode)
unsigned char *charp;
unsigned char keycode;
{
if (keyboard == OLDKEYBOARD) {
switch (keycode) {
/* keys from left to right, top to bottom */
case 0x47: {
/* Clear == pf1 */
sendvtkeyfunc('P');
break;
}
case 0x4e: {
/* - == pf2 */
sendvtkeyfunc('Q');
break;
}
case 0x46: {
/* '+' key == pf3 */
sendvtkeyfunc('R');
break;
}
case 0x42: {
/* * == pf4 */
sendvtkeyfunc('S');
break;
}
case 0x59: {
/* 7 */
sendvtkeyfunc('w');
break;
}
case 0x5b: {
/* 8 */
sendvtkeyfunc('x');
break;
}
case 0x5c: {
/* 9 */
sendvtkeyfunc('y');
break;
}
case 0x4d: {
/* / (- on vt100) */
sendvtkeyfunc('m');
break;
}
case 0x56: {
/* 4 */
sendvtkeyfunc('t');
break;
}
case 0x57: {
/* 5 */
sendvtkeyfunc('u');
break;
}
case 0x58: {
/* 6 */
sendvtkeyfunc('v');
break;
}
case 0x48: {
/* ',' */
sendvtkeyfunc('l');
break;
}
case 0x53: {
/* '1' */
sendvtkeyfunc('q');
break;
}
case 0x54: {
/* '2' */
sendvtkeyfunc('r');
break;
}
case 0x55: {
/* '3' */
sendvtkeyfunc('s');
break;
}
case 0x4c: {
/* ENTER */
sendvtkeyfunc('M');
break;
}
case 0x52: {
/* '0' */
sendvtkeyfunc('p');
break;
}
case 0x41: {
/* '.' */
sendvtkeyfunc('n');
break;
}
default: {
return(FALSE);
}
}
}
else {
/* uses Mac Plus keyboard, which has different keypad positions! */
switch (keycode) {
/* keys from left to right, top to bottom */
case 0x47: {
/* Clear == pf1 */
sendvtkeyfunc('P');
break;
}
case 0x51:
case 0x48: {
/* '=' == pf2 */
if (*charp == CTLUNDERSCORE)
/* down arrow key on mac+ */
keyputaction(RSLT_MVCR, DOWN_ARROW);
else
sendvtkeyfunc('Q');
break;
}
case 0x4b:
case 0x4d: {
/* / == pf3 */
if (*charp == CTLHAT)
/* up arrow key on mac+ */
keyputaction(RSLT_MVCR, UP_ARROW);
else
sendvtkeyfunc('R');
break;
}
case 0x43: /* + key abd */
case 0x42: /* + key mac+ */
{
/* * == pf4 */
if (*charp == CTLRBRACK)
/* right arrow key on mac+ */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
else
sendvtkeyfunc('S');
break;
}
case 0x59: {
/* 7 */
sendvtkeyfunc('w');
break;
}
case 0x5b: {
/* 8 */
sendvtkeyfunc('x');
break;
}
case 0x5c: {
/* 9 */
sendvtkeyfunc('y');
break;
}
case 0x45: /* + key abd */
case 0x46: /* + key mac+ */
{
/* '+' */
if (*charp == CTLBACKSLASH)
/* left arrow key on mac+ */
keyputaction(RSLT_MVCR, LEFT_ARROW);
else
sendvtkeyfunc('l');
break;
}
case 0x56: {
/* 4 */
sendvtkeyfunc('t');
break;
}
case 0x57: {
/* 5 */
sendvtkeyfunc('u');
break;
}
case 0x58: {
/* 6 */
sendvtkeyfunc('v');
break;
}
case 0x4e: {
/* '-' */
sendvtkeyfunc('m');
break;
}
case 0x53: {
/* '1' */
sendvtkeyfunc('q');
break;
}
case 0x54: {
/* '2' */
sendvtkeyfunc('r');
break;
}
case 0x55: {
/* '3' */
sendvtkeyfunc('s');
break;
}
case 0x4c: {
/* ENTER */
sendvtkeyfunc('M');
break;
}
case 0x52: {
/* '0' */
sendvtkeyfunc('p');
break;
}
case 0x41: {
/* '.' */
sendvtkeyfunc('n');
break;
}
case 0x7b: {
/* left arrow key saratoga */
keyputaction(RSLT_MVCR, LEFT_ARROW);
break;
}
case 0x7c: {
/* right arrow key saratoga */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
break;
}
case 0x7d: {
/* down arrow key saratoga */
keyputaction(RSLT_MVCR, DOWN_ARROW);
break;
}
case 0x7e: {
/* up arrow key saratoga */
keyputaction(RSLT_MVCR, UP_ARROW);
break;
}
default: {
return(FALSE);
}
}
}
return(TRUE);
}
/* Apple Extended (saratoga) keyboard has keys to support vt200 apps... */
vt200keychk(charp, keycode)
unsigned char *charp;
unsigned char keycode;
{
char thecode;
switch (keycode) {
case 0x72: {
/* FIND -- help saratoga */
thecode = '1';
break;
}
case 0x73: {
/* Insert Here -- home saratoga */
thecode = '2';
break;
}
case 0x74: {
/* Remove -- page up saratoga */
thecode = '3';
break;
}
case 0x75: {
/* Select -- DEL RIGHT X-> saratoga */
thecode = '4';
break;
}
case 0x77: {
/* Prev Screen -- end saratoga */
thecode = '5';
break;
}
case 0x79: {
/* Next Screen -- page down saratoga */
thecode = '6';
break;
}
default: {
return(FALSE);
}
}
/* send the code imbedded in the proper escape sequence */
sendvt102key(thecode);
return(TRUE);
}
/* interpret keycode into action, routine returns TRUE if it handles */
stdkeypad(charp, keycode)
unsigned char *charp;
unsigned char keycode;
{
if (keyboard == OLDKEYBOARD) {
switch (keycode) {
case 71: {
/* Clear == ESCAPE */
keyputaction(RSLT_ASCI, ESC);
break;
}
case 70: {
/* '+' key == + */
keyputaction(RSLT_ASCI, '+');
break;
}
case 76: {
/* ENTER == Carriage Return */
keyputaction(RSLT_ASCI, CR);
break;
}
case 66: {
/* * == * */
keyputaction(RSLT_ASCI, '*');
break;
}
case 77: {
/* / == / */
keyputaction(RSLT_ASCI, '/');
break;
}
case 72: {
/* ',' == ',' */
keyputaction(RSLT_ASCI, ',');
break;
}
default: {
return(FALSE);
}
}
}
else {
/* uses Mac Plus keyboard, which has different keypad positions! */
switch (keycode) {
case 71: {
/* Clear == ESC */
keyputaction(RSLT_ASCI, ESC);
break;
}
case 123:
case 69:
case 70: {
/* '+' key == + */
if (*charp == CTLBACKSLASH)
/* left arrow key on mac+ */
keyputaction(RSLT_MVCR, LEFT_ARROW);
else
keyputaction(RSLT_ASCI, '+');
break;
}
case 76: {
/* ENTER == CR */
keyputaction(RSLT_ASCI, CR);
break;
}
case 124:
case 67:
case 66: {
/* * == * */
if (*charp == CTLRBRACK)
/* right arrow key on mac+ */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
else
keyputaction(RSLT_ASCI, '*');
break;
}
case 126:
case 75:
case 77: {
/* / == / */
if (*charp == CTLHAT)
/* up arrow key on mac+ */
keyputaction(RSLT_MVCR, UP_ARROW);
else
keyputaction(RSLT_ASCI, '/');
break;
}
case 125:
case 81:
case 72: {
/* '=' == '=' */
if (*charp == CTLUNDERSCORE)
/* down arrow key on mac+ */
keyputaction(RSLT_MVCR, DOWN_ARROW);
else
keyputaction(RSLT_ASCI, '=');
break;
}
default: {
return(FALSE);
}
}
}
return(TRUE);
}
/* embed the code in the appropriate escape sequence, depending on the mode */
sendvtkeyfunc(thechar)
unsigned char thechar;
{
keyputaction(RSLT_ASCI, ESC);
if (keydp->mode == VT100MODE)
keyputaction(RSLT_ASCI, 'O');
else if (thechar != 'P'
&& thechar != 'Q'
&& thechar != 'R'
&& thechar != 'S')
/* vt52 function keys have no prefix, unlike other app mode keypad keys */
keyputaction(RSLT_ASCI, '?');
keyputaction(RSLT_ASCI, thechar);
}
/* imbed the code in the escape sequence for the 6 extra keys */
sendvt102key(thechar)
unsigned char thechar;
{
keyputaction(RSLT_ASCI, ESC);
keyputaction(RSLT_ASCI, '[');
keyputaction(RSLT_ASCI, thechar);
keyputaction(RSLT_ASCI, '~');
}
ibmokpnorm(keycode)
unsigned char keycode;
{
/* original keypad NORMKEYPAD */
switch (keycode) {
case 71: {
/* Clear == Clear */
keyputaction(RSLT_PFKY, CLEAR);
break;
}
case 70: {
/* '+' key == + */
keyputaction(RSLT_ASCI, '+');
break;
}
case 76: {
/* make ENTER == Enter */
keyputaction(RSLT_PFKY, ENTER);
break;
}
case 66: {
/* '*' == * */
keyputaction(RSLT_ASCI, '*');
break;
}
case 77: {
/* '/' == / */
keyputaction(RSLT_ASCI, '/');
break;
}
case 72: {
/* ',' == ',' */
keyputaction(RSLT_ASCI, ',');
break;
}
default: {
return(FALSE);
}
}
return(TRUE);
}
/* for historical reasons this code handles both keypads 1 & 2 */
ibmokp2(thechar, keycode, modifiers)
unsigned char thechar;
unsigned char keycode;
unsigned short modifiers;
{
unsigned char theact = 0;
switch (keycode) {
/* handle the keys on the keypad, which produce PF, PA, INS, CLR, & ENTER */
case 82: {
/* '0', next keypad PF key is PF13-24 or PA2 & cousins */
if (keydp->keypad == KEYPAD2) {
if (modifiers & shiftKey)
keyputaction(RSLT_PFKY, PA1);
else if (modifiers & cmdKey)
keyputaction(RSLT_PFKY, PA3);
else if (modifiers & optionKey)
keyputaction(RSLT_PFKY, CLEAR);
else
keyputaction(RSLT_PFKY, PA2);
}
else
keyputaction(RSLT_PFKY, PFSHIFT);
break;
}
case 66: {
/* * == PA1 or SHIFT */
if (keydp->keypad == KEYPAD2)
keyputaction(RSLT_PFKY, PFSHIFT);
else
keyputaction(RSLT_PFKY, PA1);
break;
}
case 77: {
/* - == PA2 or PA1 */
if (keydp->keypad == KEYPAD2)
keyputaction(RSLT_PFKY, PA1);
else {
if (modifiers & cmdKey)
keyputaction(RSLT_PFKY, PA3);
else
keyputaction(RSLT_PFKY, PA2);
}
break;
}
case 72: {
/* , == Clear */
keyputaction(RSLT_PFKY, CLEAR);
break;
}
case 76: {
/* ENTER == Enter */
keyputaction(RSLT_PFKY, ENTER);
break;
}
case 65: {
/* . == Insert */
keyputaction(RSLT_LCAC, INSRT);
break;
}
/* following this point are the 12 PF keys */
case 71: {
/* 'Clear' == PF1 */
keyputaction(RSLT_PFKY, PF1);
break;
}
case 78: {
/* '-' key == PF2 */
keyputaction(RSLT_PFKY, PF2);
break;
}
case 70: {
/* '+' key == PF3 */
keyputaction(RSLT_PFKY, PF3);
break;
}
case 89: {
/* 7 = PF4 */
keyputaction(RSLT_PFKY, PF4);
break;
}
case 91: {
/* 8 = PF5 */
keyputaction(RSLT_PFKY, PF5);
break;
}
case 92: {
/* 9 = PF6 */
keyputaction(RSLT_PFKY, PF6);
break;
}
case 86: {
/* 4 = PF7 */
keyputaction(RSLT_PFKY, PF7);
break;
}
case 87: {
/* 5 = PF8 */
keyputaction(RSLT_PFKY, PF8);
break;
}
case 88: {
/* 6 = PF9 */
keyputaction(RSLT_PFKY, PF9);
break;
}
case 83: {
/* 1 = PF10 */
keyputaction(RSLT_PFKY, PF10);
break;
}
case 84: {
/* 2 = PF11 */
keyputaction(RSLT_PFKY, PF11);
break;
}
case 85: {
/* 3 = PF12 */
keyputaction(RSLT_PFKY, PF12);
break;
}
default:
/* no keypad keys depressed, fall through */
return(FALSE);
}
return(TRUE);
}
ibmokp3(keycode)
unsigned char keycode;
{
unsigned char theact = 0;
/* do the new Lynn keypad like PAD1 but inverted */
switch (keycode) {
/* handle the keys on the keypad, which produce PF, PA, INS, CLR, & ENTER */
case 82: {
/* 0 == SHIFT */
keyputaction(RSLT_PFKY, PFSHIFT);
break;
}
case 66: {
/* '*', next keypad PF key is PA1 */
keyputaction(RSLT_PFKY, PA1);
break;
}
case 77: {
/* - == PA2 or PA1 */
keyputaction(RSLT_PFKY, PA2);
break;
}
case 72: {
/* , or + == Clear */
keyputaction(RSLT_PFKY, CLEAR);
break;
}
case 76: {
/* ENTER == Enter */
keyputaction(RSLT_PFKY, ENTER);
break;
}
case 65: {
/* . == Insert */
keyputaction(RSLT_LCAC, INSRT);
break;
}
/* following this point are the 12 PF keys */
case 83: {
/* 1 = PF1 */
keyputaction(RSLT_PFKY, PF1);
break;
}
case 84: {
/* 2 = PF2 */
keyputaction(RSLT_PFKY, PF2);
break;
}
case 85: {
/* 3 = PF3 */
keyputaction(RSLT_PFKY, PF3);
break;
}
case 86: {
/* 4 = PF4 */
keyputaction(RSLT_PFKY, PF4);
break;
}
case 87: {
/* 5 = PF5 */
keyputaction(RSLT_PFKY, PF5);
break;
}
case 88: {
/* 6 = PF6 */
keyputaction(RSLT_PFKY, PF6);
break;
}
case 89: {
/* 7 = PF7 */
keyputaction(RSLT_PFKY, PF7);
break;
}
case 91: {
/* 8 = PF8 */
keyputaction(RSLT_PFKY, PF8);
break;
}
case 92: {
/* 9 = PF9 */
keyputaction(RSLT_PFKY, PF9);
break;
}
case 71: {
/* 'Clear' == PF10 */
keyputaction(RSLT_PFKY, PF10);
break;
}
case 78: {
/* '-' key == PF11 */
keyputaction(RSLT_PFKY, PF11);
break;
}
case 70: {
/* '+' key == PF12 */
keyputaction(RSLT_PFKY, PF12);
break;
}
default:
/* no keypad keys depressed, fall through */
return(FALSE);
}
return(TRUE);
}
/* test to see if an F1-F15 key has been depressed on Saratoga kbd... */
fkeytest(keycode)
unsigned char keycode;
{
unsigned char theact = 0;
switch (keycode) {
case 122: {
/* F1 */
keyputaction(RSLT_PFKY, PF1);
break;
}
case 120: {
/* F2 */
keyputaction(RSLT_PFKY, PF2);
break;
}
case 99: {
/* F3 */
keyputaction(RSLT_PFKY, PF3);
break;
}
case 118: {
/* F4 */
keyputaction(RSLT_PFKY, PF4);
break;
}
case 96: {
/* F5 */
keyputaction(RSLT_PFKY, PF5);
break;
}
case 97: {
/* F6 */
keyputaction(RSLT_PFKY, PF6);
break;
}
case 98: {
/* F7 */
keyputaction(RSLT_PFKY, PF7);
break;
}
case 100: {
/* F8 */
keyputaction(RSLT_PFKY, PF8);
break;
}
case 101: {
/* F9 */
keyputaction(RSLT_PFKY, PF9);
break;
}
case 109: {
/* F10 */
keyputaction(RSLT_PFKY, PF10);
break;
}
case 103: {
/* F11 */
keyputaction(RSLT_PFKY, PF11);
break;
}
case 111: {
/* F12 */
keyputaction(RSLT_PFKY, PF12);
break;
}
case 105: {
/* F13 */
keyputaction(RSLT_PFKY, PF13);
break;
}
case 107: {
/* F14 */
keyputaction(RSLT_PFKY, PF14);
break;
}
case 113: {
/* F15 */
keyputaction(RSLT_PFKY, PF15);
break;
}
default:
return(FALSE);
}
return(TRUE);
}
/* ibm mac+ or > keyboard original configuration */
ibmnkpnorm(thechar, keycode)
unsigned char thechar;
unsigned char keycode;
{
/* Mac + NORMKEYPAD */
switch (keycode) {
case 71: {
/* Clear == Clear */
keyputaction(RSLT_PFKY, CLEAR);
break;
}
case 123:
case 69:
case 70: {
/* '+' key == + */
if (thechar == CTLBACKSLASH)
/* left arrow key on mac+ */
keyputaction(RSLT_MVCR, LEFT_ARROW);
else
keyputaction(RSLT_ASCI, '+');
break;
}
case 76: {
/* make ENTER == Enter */
keyputaction(RSLT_PFKY, ENTER);
break;
}
case 124:
case 67:
case 66: {
/* * == * */
if (thechar == CTLRBRACK)
/* right arrow key on mac+ */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
else
keyputaction(RSLT_ASCI, '*');
break;
}
case 126:
case 75:
case 77: {
/* / == / */
if (thechar == CTLHAT)
/* up arrow key on mac+ */
keyputaction(RSLT_MVCR, UP_ARROW);
else
keyputaction(RSLT_ASCI, '/');
break;
}
case 125:
case 81:
case 72: {
/* '=' key == PF2 */
if (thechar == CTLUNDERSCORE)
/* down arrow key on mac+ */
keyputaction(RSLT_MVCR, DOWN_ARROW);
else
keyputaction(RSLT_ASCI, '=');
break;
}
default: {
return(FALSE);
}
}
return(TRUE);
}
/* for historical reasons this code handles both keypads 1 & 2 */
ibmnkp2(thechar, keycode, modifiers)
unsigned char thechar;
unsigned char keycode;
unsigned short modifiers;
{
unsigned char theact = 0;
switch (keycode) {
/* try keypads KEYPAD1 & KEYPAD2 */
/* handle the keys on the keypad, which produce PF, PA, INS, CLR, & ENTER */
case 82: {
/* '0', next keypad PF key is PF13-24 or PA2 & cousins */
if (keydp->keypad == KEYPAD2) {
if (modifiers & shiftKey)
keyputaction(RSLT_PFKY, PA1);
else if (modifiers & cmdKey)
keyputaction(RSLT_PFKY, PA3);
else if (modifiers & optionKey)
keyputaction(RSLT_PFKY, CLEAR);
else
keyputaction(RSLT_PFKY, PA2);
}
else
keyputaction(RSLT_PFKY, PFSHIFT);
break;
}
case 78: {
/* - == PA2 or PA1 */
if (keydp->keypad == KEYPAD2)
keyputaction(RSLT_PFKY, PA1);
else {
if (modifiers & cmdKey)
keyputaction(RSLT_PFKY, PA3);
else
keyputaction(RSLT_PFKY, PA2);
}
break;
}
case 124:
case 67:
case 66: {
/* * == PA1 */
if (thechar == CTLRBRACK)
/* right arrow key on mac+ */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
else if (keydp->keypad == KEYPAD2)
keyputaction(RSLT_PFKY, PFSHIFT);
else
keyputaction(RSLT_PFKY, PA1);
break;
}
case 123:
case 69:
case 70: {
/* + == Clear */
if (thechar == CTLBACKSLASH)
/* left arrow key on mac+ */
keyputaction(RSLT_MVCR, LEFT_ARROW);
else
keyputaction(RSLT_PFKY, CLEAR);
break;
}
case 76: {
/* ENTER == Enter */
keyputaction(RSLT_PFKY, ENTER);
break;
}
case 65: {
/* . == Insert */
keyputaction(RSLT_LCAC, INSRT);
break;
}
/* following this point are the 12 PF keys */
case 71: {
/* Clear == PF1 */
keyputaction(RSLT_PFKY, PF1);
break;
}
case 125:
case 81:
case 72: {
/* '=' key == PF2 */
if (thechar == CTLUNDERSCORE)
/* down arrow key on mac+ */
keyputaction(RSLT_MVCR, DOWN_ARROW);
else
keyputaction(RSLT_PFKY, PF2);
break;
}
case 126:
case 75:
case 77: {
/* '/' key == PF3 */
if (thechar == CTLHAT)
/* up arrow key on mac+ */
keyputaction(RSLT_MVCR, UP_ARROW);
else
keyputaction(RSLT_PFKY, PF3);
break;
}
case 89: {
/* 7 = PF4 */
keyputaction(RSLT_PFKY, PF4);
break;
}
case 91: {
/* 8 = PF5 */
keyputaction(RSLT_PFKY, PF5);
break;
}
case 92: {
/* 9 = PF6 */
keyputaction(RSLT_PFKY, PF6);
break;
}
case 86: {
/* 4 = PF7 */
keyputaction(RSLT_PFKY, PF7);
break;
}
case 87: {
/* 5 = PF8 */
keyputaction(RSLT_PFKY, PF8);
break;
}
case 88: {
/* 6 = PF9 */
keyputaction(RSLT_PFKY, PF9);
break;
}
case 83: {
/* 1 = PF10 */
keyputaction(RSLT_PFKY, PF10);
break;
}
case 84: {
/* 2 = PF11 */
keyputaction(RSLT_PFKY, PF11);
break;
}
case 85: {
/* 3 = PF12 */
keyputaction(RSLT_PFKY, PF12);
break;
}
default: {
/* no keypad keys depressed, fall through */
return(FALSE);
}
}
if (theact)
keyputaction(RSLT_PFKY, theact);
return(TRUE);
}
ibmnkp3(thechar, keycode)
unsigned char thechar;
unsigned char keycode;
{
unsigned char theact = 0;
/* do the new Lynn keypad PFs calculator style, else like PAD2 */
switch (keycode) {
/* handle the keys on the keypad, which produce PF, PA, INS, CLR, & ENTER */
case 82: {
/* '0', shift */
keyputaction(RSLT_PFKY, PFSHIFT);
break;
}
case 78: {
/* - == PA2 or PA1 */
keyputaction(RSLT_PFKY, PA2);
break;
}
case 124:
case 67:
case 66: {
/* * == PA1 */
if (thechar == CTLRBRACK)
/* right arrow key on mac+ */
keyputaction(RSLT_MVCR, RIGHT_ARROW);
else
keyputaction(RSLT_PFKY, PA1);
break;
}
case 123:
case 69:
case 70: {
/* + == Clear */
if (thechar == CTLBACKSLASH)
/* left arrow key on mac+ */
keyputaction(RSLT_MVCR, LEFT_ARROW);
else
keyputaction(RSLT_PFKY, CLEAR);
break;
}
case 76: {
/* ENTER == Enter */
keyputaction(RSLT_PFKY, ENTER);
break;
}
case 65: {
/* . == Insert */
keyputaction(RSLT_LCAC, INSRT);
break;
}
/* following this point are the 12 PF keys */
case 83: {
/* 1 = PF1 */
keyputaction(RSLT_PFKY, PF1);
break;
}
case 84: {
/* 2 = PF2 */
keyputaction(RSLT_PFKY, PF2);
break;
}
case 85: {
/* 3 = PF3 */
keyputaction(RSLT_PFKY, PF3);
break;
}
case 86: {
/* 4 = PF4 */
keyputaction(RSLT_PFKY, PF4);
break;
}
case 87: {
/* 5 = PF5 */
keyputaction(RSLT_PFKY, PF5);
break;
}
case 88: {
/* 6 = PF6 */
keyputaction(RSLT_PFKY, PF6);
break;
}
case 89: {
/* 7 = PF7 */
keyputaction(RSLT_PFKY, PF7);
break;
}
case 91: {
/* 8 = PF8 */
keyputaction(RSLT_PFKY, PF8);
break;
}
case 92: {
/* 9 = PF9 */
keyputaction(RSLT_PFKY, PF9);
break;
}
case 71: {
/* Clear == PF10 */
keyputaction(RSLT_PFKY, PF10);
break;
}
case 125:
case 81:
case 72: {
/* '=' key == PF11 */
if (thechar == CTLUNDERSCORE)
/* down arrow key on mac+ */
keyputaction(RSLT_MVCR, DOWN_ARROW);
else
keyputaction(RSLT_PFKY, PF11);
break;
}
case 126:
case 75:
case 77: {
/* '/' key == PF12 */
if (thechar == CTLHAT)
/* up arrow key on mac+ */
keyputaction(RSLT_MVCR, UP_ARROW);
else
keyputaction(RSLT_PFKY, PF12);
break;
}
default:
/* no keypad keys depressed, fall through */
return(FALSE);
}
return(TRUE);
}
/* handle ibmmode keys producing ibm 7171 key sequences--pf keys
on the main keyboard w/ keypad like arrangement from
7-9 & m-. */
ibmtestpf(keycode, modifiers)
unsigned char keycode;
unsigned short modifiers;
{
unsigned char theact;
switch (keycode) {
case 26: {
/* '7' */
theact = PF1;
break;
}
case 28: {
/* '8' */
theact = PF2;
break;
}
case 25: {
/* '9' */
theact = PF3;
break;
}
case 32: {
/* 'u' */
theact = PF4;
break;
}
case 34: {
/* 'i' */
theact = PF5;
break;
}
case 31: {
/* 'o' */
theact = PF6;
break;
}
case 38: {
/* 'j' */
theact = PF7;
break;
}
case 40: {
/* 'k' */
theact = PF8;
break;
}
case 37: {
/* 'l' */
theact = PF9;
break;
}
case 46: {
/* 'm' */
theact = PF10;
break;
}
case 43: {
/* ',' */
theact = PF11;
break;
}
case 47: {
/* '.' */
theact = PF12;
break;
}
default:
return(FALSE);
break;
}
if ( (modifiers & shiftKey) ) {
keyputaction(RSLT_PFKY, PFSHIFT);
}
keyputaction(RSLT_PFKY, theact);
return(TRUE);
}
/* action queue routines */
/* add an action to the queue in the keydp context */
void
keyputaction(itemclass, item)
unsigned char itemclass, item;
{
if (keydp->q_cnt >= MAX_Q) {
beep();
return;
}
keydp->q_cnt++;
keydp->actqueue[keydp->q_head].class = itemclass;
keydp->actqueue[keydp->q_head++].entry = item;
if (keydp->q_head >= MAX_Q)
keydp->q_head = 0;
}
/* add an action to the queue in the emdp context */
void
putaction(itemclass, item)
unsigned char itemclass, item;
{
if (emdp->q_cnt >= MAX_Q) {
beep();
return;
}
emdp->q_cnt++;
emdp->actqueue[emdp->q_head].class = itemclass;
emdp->actqueue[emdp->q_head++].entry = item;
if (emdp->q_head >= MAX_Q)
emdp->q_head = 0;
}
/* return a pointer to the next action struct */
/* the following use emdp since they are called during token interpretation
for the emulator */
struct token *
getaction()
{
struct token * tokep;
if (emdp->tokenhold)
++emdp->tokencount;
else
--emdp->q_cnt;
tokep = &emdp->actqueue[emdp->q_tail];
if (++emdp->q_tail >= MAX_Q)
emdp->q_tail = 0;
return( (struct token *) tokep);
}
/* return a pointer to the next action struct */
ungetaction(tokep)
struct token * tokep;
{
if (emdp->q_cnt >= MAX_Q)
return(-1);
if (emdp->tokenhold)
--emdp->tokencount;
else
++emdp->q_cnt;
if (--emdp->q_tail < 0)
emdp->q_tail = MAX_Q - 1;
emdp->actqueue[emdp->q_tail].class = tokep->class;
emdp->actqueue[emdp->q_tail].entry = tokep->entry;
}
/* save tokens we return from the q for later looping */
tokenloop(count)
int count;
{
if (emdp->tokenhold) {
/* loop already active */
if (count == 0) {
/* 0 count terminates a loop */
looprewind();
return(0);
}
else {
/* TODO not sure this works correctly... cancel the current loop */
emdp->q_cnt -= emdp->tokencount; /* release tokens */
}
}
emdp->tokenhold = TRUE;
emdp->loopcount = count;
emdp->tokencount = 0;
return(0);
}
/* loop back to the token just after the first loop argumnet
encountered and decrement the loop counter; if counter goes to zero,
terminate loop */
looprewind()
{
if (!emdp->tokenhold)
return(-1);
if ((emdp->loopcount == -1) || emdp->loopcount) {
/* loop again */
if (emdp->loopcount != -1)
/* decrement if not eternal loop */
--emdp->loopcount;
emdp->q_tail -= emdp->tokencount;
if (emdp->q_tail < 0)
emdp->q_tail += MAX_Q;
}
else {
/* done with loop */
emdp->q_cnt -= emdp->tokencount; /* release tokens */
emdp->tokenhold = FALSE;
}
emdp->tokencount = 0;
}
matchtoken(thechar)
unsigned char thechar;
{
struct token * tkptr;
if (emdp->tokencount < emdp->q_cnt) {
tkptr = getaction();
if (tkptr->class == RSLT_ASCI) {
if (tkptr->entry != thechar) {
looprewind();
return(FALSE);
}
else {
/* find out whether next entry is end of match */
if (emdp->tokencount < emdp->q_cnt) {
tkptr = getaction();
ungetaction(tkptr);
if (tkptr->class == RSLT_ASCI) {
/* failure ! */
return(FALSE);
}
}
/* else fall through, we have succeeded */
}
}
}
/* success on end of available tokens */
emdp->q_cnt -= emdp->tokencount; /* release tokens */
emdp->tokenhold = FALSE;
emdp->matchinput = FALSE;
return(TRUE);
}
flushtokenmatch()
{
struct token * tkptr;
looprewind();
emdp->tokenhold = FALSE;
while (emdp->q_cnt) {
/* dump the match string */
if (emdp->tokencount < emdp->q_cnt) {
tkptr = getaction();
if (tkptr->class == RSLT_ASCI)
continue;
ungetaction(tkptr);
break;
}
}
emdp->matchinput = FALSE;
}
/* dump all actions in the queue */
flushactions(twp)
struct winds * twp;
{
twp->q_head = 0;
twp->q_tail = 0;
twp->q_cnt = 0;
twp->tokenhold = FALSE;
twp->matchinput = FALSE;
twp->emdisable = FALSE;
twp->loopcount = 0;
twp->tokencount = 0;
resumetokens(twp); /* abort any DELAY tokens */
if (twp->emwindow && twp->macroexecuting) {
/* reset the macro flag */
twp->macroexecuting = FALSE;
InvalRect(&twp->macrorect);
/* and reset the button bar */
reset25(twp);
}
}
/* the following assembly language routines interface to the old System 4.1
key mapping interface, now superseded by the Script Mgr */
long * keytrans; /* actually void * (*keytrans)() ? but who cares ? */
long * key1tran; /* the original system key handling routine */
#asm
; this routine resets the option key flag so NO option key remapping is done by
; the standard macintosh key configuration code; the option-key-down bit is
; cleared
public keyend_
OrigA5 EQU $904
cseg
public keytrap_
keytrap_:
move.l a5,a3
move.l (OrigA5),A5
; end of save routine
bclr #2,d1 ; clear option key bit
norm_:
move.l _key1tran,a2
jsr (a2)
keyend_:
move.l a3,a5
rts
#endasm
keyclose()
{
if (GetTrapAddress(0x9f) != GetTrapAddress(0xb5) ) {
setscript(0L); /* restore standard system script on exit() */
}
else {
if (!keytron)
return(0);
keytron = FALSE;
#asm
move.l _keytrans,a2
move.l _key1tran,(a2)
#endasm
}
}
/* patch in a key resource desc with the Script Mgr which will pass
the option keys */
keyinit()
{
long script;
if (GetTrapAddress(0x9f) != GetTrapAddress(0xb5) ) {
/* if script manager is not == Unimplemented, use it */
setscript((long) EINUSCRIPT);
}
else {
/* add our old System key filter to preprocess keys before the standard one */
if (keytron)
return(0);
keytron = TRUE;
keytrans = 0x29e;
key1tran = (long *) *keytrans;
/* *keytrans = (long *) keytrap; */
#asm
move.l _keytrans,a2
lea keytrap_,a1
move.l a1,(a2)
#endasm
}
exit_hook(keyclose);
}